package org.suyafei.listener;

import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.suyafei.model.EventMessage;
import org.suyafei.service.ProductOrderService;

/**
 * @author 宿某人
 * @Date: 2022/02/10/10:58 上午
 * @Description:
 */
@Component
@Slf4j
@RabbitListener(queuesToDeclare = {@Queue("order.close.queue"), @Queue("order.update.queue")})
public class ProductOrderMQListener {


    @Autowired
    private ProductOrderService productOrderService;


    @RabbitHandler
    public void productOrderHandler(EventMessage eventMessage, Message message, Channel channel) {
        log.info("监听消息ProductOrderMQListener message消息内容：{}", message);
        try {

            productOrderService.handleProductOderMessage(eventMessage);
            productOrderService.closeProductOrder(eventMessage);

        } catch (Exception e) {
            log.error("消费失败:{}", eventMessage);
        }
        log.info("消费成功:{}", eventMessage);
    }
}
